package com.cat.chapter048;

import java.io.*;
import java.util.Arrays;

/**
 * @author cat
 * @description https://www.nowcoder.com/practice/50e1a93989df42efb0b1dec386fb4ccc
 * @create 2025/7/17 19:35
 * @since JDK17
 */

public class Solution02 {
    static int n, m, k, MAXN = 1010;
    static long[][] diff = new long[MAXN][MAXN];
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter pr = new PrintWriter(new OutputStreamWriter(System.out));
    static StreamTokenizer tokenizer = new StreamTokenizer(br);

    public static void add(int a, int b, int c, int d, int k) {
        diff[a][b] += k;
        diff[a][d + 1] -= k;
        diff[c + 1][b] -= k;
        diff[c + 1][d + 1] += k;
    }
    public static void main(String[] args) throws IOException {
        tokenizer.nextToken();
        n = ((int) tokenizer.nval);
        tokenizer.nextToken();
        m = ((int) tokenizer.nval);
        tokenizer.nextToken();
        k = ((int) tokenizer.nval);
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                tokenizer.nextToken();
                add(i, j, i, j, ((int) tokenizer.nval));
            }
        }

        for (int i = 0; i < k; i++) {
            int a, b, c, d, e;
            tokenizer.nextToken();
            a = ((int) tokenizer.nval);
            tokenizer.nextToken();
            b = ((int) tokenizer.nval);
            tokenizer.nextToken();
            c = ((int) tokenizer.nval);
            tokenizer.nextToken();
            d = ((int) tokenizer.nval);
            tokenizer.nextToken();
            e = ((int) tokenizer.nval);
            add(a, b, c, d, e);
        }

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {  //
                diff[i][j] += diff[i - 1][j] + diff[i][j - 1] - diff[i - 1][j - 1];
            }
        }

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                pr.print(diff[i][j] + " ");
            }
            pr.println();
        }

        for (int i = 0; i <= n + 1; i++) {
            Arrays.fill(diff[i], 0);
        }
        br.close();
        pr.flush();
        pr.close();
    }
}
